import { _decorator, Component, Input, Node, tween, Tween, Vec3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('Circle')
export class Circle extends Component {

    @property([Node])
    private CircleArr: Node[] = [];

    //当前索引
    public currentIndex: number = 0;

    //是否被选中
    public IamChoose: boolean = false;

    //
    public ShowCircle: Node = null;

    /**
     * 更新
     */
    public UpdateCircle(_index: number) {
        this.IamChoose = false;
        this.currentIndex = _index;
        for (let i = 0; i < this.CircleArr.length; i++) {
            this.CircleArr[i].setPosition(new Vec3(0, 0, 0))
            this.CircleArr[i].active = i == _index;

            if (i == _index) {
                this.ShowCircle = this.CircleArr[i]
            }

        }
        this.node.setScale(new Vec3(1, 1, 1));
    }

    /**
     * 播放出现动画
     */
    public PlayAni(_delay: number) {
        Tween.stopAllByTarget(this.ShowCircle);
        this.ShowCircle.setWorldPosition(new Vec3(375, 150))
        tween(this.ShowCircle).delay(0.1 * _delay).to(0.3, { position: new Vec3(0, 0, 0) }, { easing: 'backOut' }).start();
    }

    /**
    * 播放出现动画
    */
    public PlayAni1(_delay: number, _pos: Vec3) {
        Tween.stopAllByTarget(this.ShowCircle);
        this.node.setScale(new Vec3(1, 1, 1));
        tween(this.ShowCircle).delay(0.1 * _delay).to(0.3, { worldPosition: _pos }, { easing: 'backIn' }).call(() => {
            this.ShowCircle.active = false;
        }).start();
    }
}


